home *** CD-ROM | disk | FTP | other *** search
- Path: news.iadfw.net!usenet
- From: arlyn@airmail.net (Arlyn Chesley)
- Newsgroups: comp.std.c
- Subject: Need Help with stacks - advanc_c.cpp (0/1)
- Date: Sat, 24 Feb 1996 09:32:21 GMT
- Organization: customer of Internet America
- Message-ID: <4gnt60$ois@news-f.iadfw.net>
- NNTP-Posting-Host: dal22-08.ppp.iadfw.net
- X-Newsreader: Forte Free Agent v0.55
-
- I am having diffficulty getting info back from stacks. If anyone out
- there can help it would be appreciated.
-
- I have the main included as an attachment and will copy in my include
- file as I do not know if I can attach 2 files. I am using a Borland
- C++ compiler but am programming in"C".
-
- /**************************************************************************
- * File Name: p1.cpp
- * Description: Using Stacks
- * Author: Arlyn K. Chesley
- * Date: 2/16/96 started
- *
- * This file contains four functions that are used in conjunction
- * with the main of stacks.cpp
- * The four functins are as follows
- * stack_new - a function used to create new stacks
- * stack_push - used to push items onto the stack
- * stack_pop - used to pop items off of the stack for use
- * stack_free - used to free the memory previously allocated to
- stacks
- * I = an Input to the function, O = an output from the function
- *************************************************************************/
- int stack_new(
- int size, /* I-size of a single element */
- int count, /* I-Maximum number of data elements */
- long *k) /* O-Key to the newly created stack area */
- {
- /*************************************************************
- * Structure definition for allocation of new stacks
- **************************************************************/
- struct str_hdr
- {
- int tos;
- int size;
- int count;
- char *data;
- };
-
- struct str_hdr *H;
- H=(str_hdr*)malloc(sizeof(str_hdr));
- H->tos = 0;
- H->size = size;
- H->count = count;
- H->data =(char*)malloc(sizeof(size * count));
- *k =(long)H; /* pointer back to main for key */
-
- if(H == NULL)
- return(RC_MALLOC_ERROR);
- else
- return(RC_OK);
- }
-
- int stack_push(
- long key, /* I-Key to the stack to operate upon */
- char *data) /* I-Pointer to data element to be saved */
- {
- if(data != NULL)
- {
- (char)key = *data;
- key++;
- return RC_OK;
- }
- else
- {
- return RC_OVERFLOW;
- }
- }
-
- int stack_pop(
- long key, /* I-Key to the stack to operate upon */
- char *data) /* O-Place retrieved data is to be copied to */
- {
- if(data != NULL)
- {
- key = *data;
- key--;
- return(RC_OK);
- }
- else if(data == NULL)
- return(RC_UNDERFLOW);
- else
- return(0);
- }
-
- int stack_free(
- long key) /* I-Key to the stack to operate upon */
- {
- free((long *) key);
- return(0);
- }
-
-
-